home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / gamma-bros.swf / scripts / __Packages / classes / enemy / HeadB.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  10.9 KB  |  378 lines

  1. class classes.enemy.HeadB
  2. {
  3.    var x;
  4.    var y;
  5.    var moveScript;
  6.    var id;
  7.    var clip;
  8.    var colorR;
  9.    var trans;
  10.    var colorTrans;
  11.    var f2;
  12.    var dir;
  13.    var axis;
  14.    var xDest;
  15.    var yDest;
  16.    var ep;
  17.    var oldDir;
  18.    var xMov = 0;
  19.    var yMov = 0;
  20.    var xMovT = 0;
  21.    var yMovT = 0;
  22.    var speedOrig = 8;
  23.    var speed = 8;
  24.    var xDestMet = false;
  25.    var yDestMet = false;
  26.    var c = 0;
  27.    var life = 5;
  28.    var nc = 0;
  29.    var xA = 0;
  30.    var yA = 0;
  31.    var nudging = false;
  32.    var hc = 0;
  33.    var power = 15;
  34.    var flashing = false;
  35.    var flashC = 0;
  36.    var Name = "headB";
  37.    function HeadB(px, py, pmoveScript, pid)
  38.    {
  39.       this.x = px;
  40.       this.y = py;
  41.       this.moveScript = pmoveScript.slice();
  42.       this.id = pid;
  43.       _root.d = _root.d + 1;
  44.       this.clip = _root.attachMovie("headB","headB" + this.id + "Clip",_root.d + 50000);
  45.       this.clip._x = this.x;
  46.       this.clip._y = this.y;
  47.       this.speed *= _root.dif.speed;
  48.       this.speedOrig = this.speed;
  49.       this.life *= _root.dif.life;
  50.       this.speedVar();
  51.       this.colorR = _root.randRange(-10,30);
  52.       this.trans = new flash.geom.Transform(this.clip);
  53.       this.colorTrans = new flash.geom.ColorTransform(1,1,1,1,this.colorR,this.colorR,this.colorR,0);
  54.       this.trans.colorTransform = this.colorTrans;
  55.       this.parseMoveScript();
  56.       if(_root.flashing)
  57.       {
  58.          this.flashing = true;
  59.          _root.flashing = false;
  60.       }
  61.       _root.stats.created = _root.stats.created + 1;
  62.    }
  63.    function nudge(pxA, pyA, pscale)
  64.    {
  65.       this.nc = 0;
  66.       this.nudging = true;
  67.       var _loc2_ = pscale / 100;
  68.       this.xA = pxA * _loc2_;
  69.       this.yA = pyA * _loc2_;
  70.    }
  71.    function speedVar()
  72.    {
  73.       if(random(3) == 1)
  74.       {
  75.          this.speed *= _root.randRange2(0.9998,1.0002);
  76.       }
  77.    }
  78.    function bombed(num)
  79.    {
  80.       this.f2 = "death";
  81.    }
  82.    function parseMoveScript()
  83.    {
  84.       this.dir = this.moveScript[0];
  85.       if(this.dir == "break")
  86.       {
  87.          delete this.moveScript;
  88.          this[this.axis + "MovT"] = 0;
  89.          this.f2 = "wander";
  90.          if(random(10) > 2)
  91.          {
  92.             this.dir = _root.getDir(this.x,this.y);
  93.             this.axis = !(this.dir == "L" || this.dir == "R") ? "y" : "x";
  94.             this[this.axis + "MovT"] = !(this.dir == "L" || this.dir == "U") ? this.speed : -1 * this.speed;
  95.             this.speedVar();
  96.          }
  97.          else
  98.          {
  99.             this.axis = random(10) <= 4 ? "y" : "x";
  100.             this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  101.             this.getDirString();
  102.          }
  103.       }
  104.       else
  105.       {
  106.          this[this.axis + "MovT"] = 0;
  107.          this.f2 = "gotoXYDest";
  108.          this.axis = !(this.dir == "L" || this.dir == "R") ? "y" : "x";
  109.          this[this.axis + "MovT"] = !(this.dir == "L" || this.dir == "U") ? this.speed : -1 * this.speed;
  110.          this.speedVar();
  111.          if(this.dir == "L" || this.dir == "U")
  112.          {
  113.             this[this.axis + "Dest"] = this[this.axis] - this.moveScript[1];
  114.          }
  115.          else
  116.          {
  117.             this[this.axis + "Dest"] = this[this.axis] + this.moveScript[1];
  118.          }
  119.          this.moveScript.splice(0,2);
  120.       }
  121.    }
  122.    function gotoXYDest()
  123.    {
  124.       if(Math.abs(this[this.axis + "Dest"] - this[this.axis]) < this.speed + 1)
  125.       {
  126.          if(this.axis == "x")
  127.          {
  128.             this.x = this.xDest;
  129.          }
  130.          else
  131.          {
  132.             this.y = this.yDest;
  133.          }
  134.          this.parseMoveScript();
  135.       }
  136.    }
  137.    function getDirString()
  138.    {
  139.       if(this.xMovT < -1)
  140.       {
  141.          this.dir = "L";
  142.       }
  143.       else if(this.xMovT > 1)
  144.       {
  145.          this.dir = "R";
  146.       }
  147.       else if(this.yMovT > 1)
  148.       {
  149.          this.dir = "D";
  150.       }
  151.       else if(this.yMovT < -1)
  152.       {
  153.          this.dir = "U";
  154.       }
  155.    }
  156.    function wander()
  157.    {
  158.       if(random(100) > 70 || (this.x > 950 || this.x < 50 || this.y < 50 || this.y > 550))
  159.       {
  160.          if(random(20) > 18)
  161.          {
  162.             this[this.axis + "MovT"] = 0;
  163.             this.f2 = "wait";
  164.             this.c = 0;
  165.             this.ep = _root.randRange(30,120);
  166.             this.ep *= 1 / _root.dif.speed;
  167.          }
  168.          else if(random(10) > 1)
  169.          {
  170.             this.dir = _root.getDir(this.x,this.y);
  171.             this[this.axis + "MovT"] = 0;
  172.             this.axis = !(this.dir == "L" || this.dir == "R") ? "y" : "x";
  173.             this[this.axis + "MovT"] = !(this.dir == "L" || this.dir == "U") ? this.speed : -1 * this.speed;
  174.             this.speedVar();
  175.          }
  176.          else
  177.          {
  178.             this[this.axis + "MovT"] = 0;
  179.             this.axis = random(10) <= 4 ? "y" : "x";
  180.             this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  181.             this.getDirString();
  182.          }
  183.       }
  184.    }
  185.    function wait()
  186.    {
  187.       this.c = this.c + 1;
  188.       if(this.c >= this.ep)
  189.       {
  190.          this.f2 = "wander";
  191.          if(random(10) > 2)
  192.          {
  193.             this.dir = _root.getDir(this.x,this.y);
  194.             this.axis = !(this.dir == "L" || this.dir == "R") ? "y" : "x";
  195.             this[this.axis + "MovT"] = !(this.dir == "L" || this.dir == "U") ? this.speed : -1 * this.speed;
  196.             this.speedVar();
  197.          }
  198.          else
  199.          {
  200.             this.axis = random(10) <= 4 ? "y" : "x";
  201.             this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  202.             this.getDirString();
  203.          }
  204.       }
  205.       if(random(100) > 95)
  206.       {
  207.          var _loc3_ = ["L","R","F"];
  208.          this.dir = _loc3_[random(_loc3_.length)];
  209.       }
  210.    }
  211.    function attacking()
  212.    {
  213.    }
  214.    function death()
  215.    {
  216.       _root.stats.destroyed = _root.stats.destroyed + 1;
  217.       _root.stats.score += 750;
  218.       _root.powerUp(this.x,this.y,94);
  219.       _root.createExploA([this.x + this.clip._width / 2,this.y + this.clip._height / 2,_root.randRange(60,80),_root.randRange(75,100),"Blue"]);
  220.       var _loc3_ = 0;
  221.       var _loc4_ = random(3);
  222.       while(_loc3_ < _loc4_)
  223.       {
  224.          _root.createShrapnel([this.x + this.clip._width / 2,this.y + this.clip._height / 2,"headB","Blue"]);
  225.          _loc3_ = _loc3_ + 1;
  226.       }
  227.       _root.createEnemySoul([this.x + this.clip._width / 2,this.y + this.clip._height / 2,"blue"]);
  228.       _root.audio.playLevel4("headX" + (random(3) + 1),_root.randRange(15,25));
  229.       _root.removeChar("headB" + this.id);
  230.       this.f2 = "";
  231.    }
  232.    function death2()
  233.    {
  234.       _root.removeChar("headB" + this.id);
  235.       this.f2 = "";
  236.    }
  237.    function main()
  238.    {
  239.       if(this.flashing)
  240.       {
  241.          this.flashC = this.flashC + 1;
  242.          var _loc8_ = 275 - this.flashC * 10;
  243.          this.colorTrans.greenOffset = _loc8_;
  244.          this.colorTrans.redOffset = _loc8_ / 2;
  245.          this.colorTrans.blueOffset = _loc8_;
  246.          this.trans.colorTransform = this.colorTrans;
  247.          if(this.flashC == 27)
  248.          {
  249.             this.colorTrans.greenOffset = 0;
  250.             this.colorTrans.redOffset = 0;
  251.             this.colorTrans.blueOffset = 0;
  252.             this.trans.colorTransform = this.colorTrans;
  253.             delete this.flashing;
  254.             delete this.flashC;
  255.          }
  256.       }
  257.       this[this.f2]();
  258.       if(this.oldDir != this.dir)
  259.       {
  260.          if(this.oldDir == undefined || this.dir == "F")
  261.          {
  262.             this.clip.body.eyes.gotoAndStop(this.dir);
  263.          }
  264.          else if(this.dir == "U" || this.dir == "D")
  265.          {
  266.             this.clip.body.eyes.gotoAndStop(this.oldDir);
  267.          }
  268.          else if(random(3) > 0)
  269.          {
  270.             if(this.dir == "R")
  271.             {
  272.                this.clip.body.eyes.gotoAndPlay("LtoR");
  273.             }
  274.             else
  275.             {
  276.                this.clip.body.eyes.gotoAndPlay("RtoL");
  277.             }
  278.          }
  279.          else
  280.          {
  281.             this.clip.body.eyes.gotoAndPlay("spin" + this.dir);
  282.          }
  283.       }
  284.       this.oldDir = this.dir;
  285.       if(this.nudging)
  286.       {
  287.          this.xA *= 0.5;
  288.          this.yA *= 0.5;
  289.          this.nc = this.nc + 1;
  290.          _loc8_ = 255 - this.nc * 17;
  291.          this.colorTrans.blueOffset = _loc8_;
  292.          this.colorTrans.greenOffset = _loc8_ / 2;
  293.          this.trans.colorTransform = this.colorTrans;
  294.          if(this.nc == 15)
  295.          {
  296.             this.xA = this.yA = 0;
  297.             this.nudging = false;
  298.             this.colorTrans.blueOffset = this.colorR;
  299.             this.colorTrans.greenOffset = this.colorR;
  300.             this.trans.colorTransform = this.colorTrans;
  301.          }
  302.       }
  303.       var _loc4_ = 0;
  304.       var _loc7_ = _root.broShots.length;
  305.       while(_loc4_ < _loc7_)
  306.       {
  307.          var _loc6_ = _root.broShots[_loc4_] + "Clip";
  308.          if(this.clip.hitTest(_root[_loc6_]))
  309.          {
  310.             var _loc3_ = _root.broShots[_loc4_];
  311.             var _loc5_ = this.life;
  312.             this.life -= _root[_loc3_].power;
  313.             if(this.life < 1)
  314.             {
  315.                this.f2 = "death";
  316.             }
  317.             else
  318.             {
  319.                this.nudge(_root[_loc3_].xMov,_root[_loc3_].yMov,10);
  320.                _root.audio.playLevel4("headHit" + (random(4) + 1),_root.randRange(18,28));
  321.                this[this.axis + "MovT"] = 0;
  322.                this.axis = random(10) <= 4 ? "y" : "x";
  323.                this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  324.                this.getDirString();
  325.             }
  326.             _root[_root.char].fc = _root[_root.char].fireFreq - _root.rapidVar;
  327.             _root[_loc3_].exploX = this.x + this.clip._width / 2;
  328.             _root[_loc3_].exploY = this.y + this.clip._height / 2;
  329.             _root[_loc3_].hit(_loc5_);
  330.             break;
  331.          }
  332.          _loc4_ = _loc4_ + 1;
  333.       }
  334.       if(this.clip.hitTest(_root[_root.char + "Clip"]))
  335.       {
  336.          _root[_root.char].stealCoins(10);
  337.          _root[_root.char].hit(this.xMov,this.yMov,100,this.power);
  338.          this.f2 = "death";
  339.       }
  340.       if(this.x > 1050 || this.x < -50 || this.y < -50 || this.y > 650)
  341.       {
  342.          this.f2 = "death2";
  343.       }
  344.       if(this.xMovT < this.xMov)
  345.       {
  346.          this.xMov -= 0.3;
  347.       }
  348.       else if(this.xMovT > this.xMov)
  349.       {
  350.          this.xMov += 0.3;
  351.       }
  352.       else
  353.       {
  354.          this.xMov = this.xMovT;
  355.       }
  356.       if(this.yMovT < this.yMov)
  357.       {
  358.          this.yMov -= 0.3;
  359.       }
  360.       else if(this.yMovT > this.yMov)
  361.       {
  362.          this.yMov += 0.3;
  363.       }
  364.       else
  365.       {
  366.          this.yMov = this.yMovT;
  367.       }
  368.       if(random(100) > 98)
  369.       {
  370.          this.clip.body.eyes.clip.gotoAndPlay("blink");
  371.       }
  372.       this.x += this.xMov + this.xA;
  373.       this.y += this.yMov + this.yA + 0.5 * Math.sin(this.hc += 0.1);
  374.       this.clip._x = this.x;
  375.       this.clip._y = this.y;
  376.    }
  377. }
  378.